#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>
void Merge(int* arr, int low, int mid, int high)
{
	int* p = (int*)malloc((high - low + 1)*sizeof(int));
	int left_low = low;
	int left_high = mid;
	int right_low = mid + 1;
	int right_high = high;
	int k = 0;
	for (k = 0; left_low <= left_high&&right_low <= right_high; k++)
	{
		if (arr[left_low] < arr[right_low])
		{
			p[k] = arr[left_low];
			left_low++;
		}
		else
		{
			p[k] = arr[right_low];
			right_low++;
		}
	}
	if (left_low <= left_high)
	{
		memcpy(p + k, arr + left_low, sizeof(int)*(left_high - left_low + 1));
	}
	if (right_low <= right_high)
	{
		memcpy(p + k, arr + right_low, sizeof(int)*(right_high - right_low + 1));
	}
	for (int i = 0; i < high - low + 1; i++)
	{
		arr[low + i] = p[i];
	}
	free(p);
	p = NULL;
}
void Sort(int* arr, int first, int last)
{
	if (first < last)
	{
		int mid = (first + last) / 2;
		Sort(arr, first, mid);
		Sort(arr, mid + 1, last);
		Merge(arr, first, mid, last);
	}
}
int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	int Peo[10000] = { 0 };
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &Peo[i]);
	}
	int time = 0;
	if (m>=n)
	{
		Sort(Peo, 0, n-1);
		time = Peo[n - 1];
	}
	else
	{
		int q = m;
		while (q < n)
		{
			int p = 0;
			Sort(Peo, 0, m-1);
			int temp = Peo[0];
			for (int i = 0; i < m; i++)
			{
				time += Peo[0];
				Peo[i] -= temp;
				
			}
			while (Peo[p] == 0 && q < n)
			{
				Peo[p] = Peo[q];
				p++;
				q++;
			}
		}
		Sort(Peo, 0, m - 1);
		time += Peo[m - 1];
	}
	printf("%d", time);
	return 0;
}